<!--
 * @Author: 高瑞寒 15932717091@163.com
 * @Date: 2022-05-17 22:48:58
 * @LastEditTime: 2022-05-20 21:59:31
 * @LastEditors: 高瑞寒 15932717091@163.com
 * @Description:
-->
<template>
<div id="guide-breadcrumb"></div>
  <el-breadcrumb separator="/" class="breadcrumb" id='guide-breadcrumbTitle'>
    <transition-group name="breadcrumb">
      <el-breadcrumb-item
        v-for="(item, index) in breadcrumbData"
        :key="item.path"
      >
        <span class="no-redirect" v-if="index === breadcrumbData.length - 1">{{
          generateTitle(item.meta.title)
        }}</span>
        <a class="redirect" v-else @click.prevent="triggerClick(item.path)">{{
          generateTitle(item.meta.title)
        }}</a>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router'
import { watch, ref } from 'vue'
import { useStore } from 'vuex'
import { generateTitle } from '@/utils/i18n'
const route = useRoute()
const router = useRouter()
const triggerClick = (path) => {
  console.log(path)
  router.push(path)
}

const breadcrumbData = ref([])
const getBreadcrumbRoute = () => {
  breadcrumbData.value = route.matched.filter(
    (item) => item.meta.title && item.path
  )
}
watch(
  route,
  () => {
    getBreadcrumbRoute()
  },
  { immediate: true }
)

const store = useStore()
// eslint-disable-next-line
const breadcrumbHoverColor = store.getters.cssVar.menuBg
</script>

<style lang="scss" scoped>
.breadcrumb {
  display: inline-block;
  font-size: 14px;
  line-height: 50px;
  margin-left: 8px;

  :deep(.no-redirect) {
    color: #97a8be;
    cursor: text;
  }
  .redirect {
    color: #666;
    font-weight: 600;
  }

  .redirect:hover {
    // 将来需要进行主题替换，所以这里不去写死样式
    color: v-bind(breadcrumbHoverColor);
  }
}
</style>
